package org.clever.arkdemo.livestream.modules.media.controller;

import org.clever.arkdemo.livestream.common.stream.domain.service.LiveStream;
import org.clever.arkdemo.livestream.common.stream.domain.vo.LiveStreamPath;
import org.clever.arkdemo.livestream.modules.media.dto.response.PlayStreamPathVO;
import org.clever.arkdemo.livestream.modules.media.dto.response.PushStreamPathVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/stream")
public class StreamApi {
    @Autowired(required = false)
    private LiveStream liveStream;

    /**
     * 获得推流地址
     */
    @RequestMapping("/getStreamPath")
    public PushStreamPathVO getPushStreamPath(String streamName) {
        LiveStreamPath streamPath = liveStream.getStreamPath(streamName, 0);
        PushStreamPathVO pushStreamPathVO = new PushStreamPathVO();
        pushStreamPathVO.setRtmp(streamPath.getPushPath().getRtmp());
        pushStreamPathVO.setObsPath(streamPath.getPushPath().getObsPath());
        pushStreamPathVO.setObsKey(streamPath.getPushPath().getObsKey());
        return pushStreamPathVO;
    }

    @RequestMapping("/getStreamPlayPath")
    public PlayStreamPathVO getStreamPlayPath(String streamName) {
        LiveStreamPath streamPath = liveStream.getStreamPath(streamName, 0);
        PlayStreamPathVO playStreamPathVO = new PlayStreamPathVO();
        playStreamPathVO.setRtmp(streamPath.getPlayPath().getRtmp());
        playStreamPathVO.setFlv(streamPath.getPlayPath().getFlv());
//        playStreamPathVO.setHls(streamPath.getPlayPath().getHls());
        return playStreamPathVO;
    }

}
